﻿Imports System.Configuration
Imports System.IO

Namespace My

    'This class allows you to handle specific events on the settings class:
    ' The SettingChanging event is raised before a setting's value is changed.
    ' The PropertyChanged event is raised after a setting's value is changed.
    ' The SettingsLoaded event is raised after the setting values are loaded.
    ' The SettingsSaving event is raised before the setting values are saved.
    Partial Friend NotInheritable Class MySettings

        Private Sub MySettings_SettingsLoaded(ByVal sender As Object, ByVal e As SettingsLoadedEventArgs) Handles Me.SettingsLoaded
            Me.PrepareConnectionString()
        End Sub

        ''' <summary>
        ''' Nodig om de connectiestrings juist in te stellen in alle gevallen.
        ''' Wordt opgeroepen vanuit MainForm
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub PrepareConnectionString()
            ' TODO: als je ontwikkelt onder Windows 32 bit, dan moet de x86 weg! 
            If (AppDomain.CurrentDomain.BaseDirectory.Contains("TestResults")) Then
                ' voor unit tests
                Dim di As New DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory)
                Dim dbFileName As String = Path.Combine(di.Parent.Parent.Parent.FullName, "FairShop\bin\x86\Debug\App_Data\fairshopOefen.mdb")
                Me.Item("fairShopConnectionString") = Me.Item("fairShopConnectionString").ToString().Replace("|DataDirectory|\bin\x86\Debug\App_Data\fairshopOefen.mdb", _
                    dbFileName)
            Else
                ' De connectionstring in My.Settings moet zo staan om de datasets te kunnen aanpassen in Visual Studio.
                ' Tijdens het runnen passen we ze aan naar een andere waarde.
                If (Utility.IsOefenVersie()) Then
                    Me.Item("fairShopConnectionString") = Me.Item("fairShopConnectionString").ToString().Replace("|DataDirectory|\bin\x86\Debug\App_Data\fairshopOefen.mdb", "|DataDirectory|\App_Data\FairShopOefen.mdb")
                Else
                    Me.Item("fairShopConnectionString") = Me.Item("fairShopConnectionString").ToString().Replace("|DataDirectory|\bin\x86\Debug\App_Data\fairshopOefen.mdb", "|DataDirectory|\App_Data\FairShop.mdb")
                End If
            End If
        End Sub

    End Class

End Namespace
